
#include <iostream>
#include <string>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <cstdint>
#include <strings.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cstring>
using namespace std;
int main(int argc,char* argv[]){
    if(argc!=3){
        cout<<"wring"<<endl;
        exit(0);
    }
    string serverip = argv[1];
    uint16_t serverport = stoi(argv[2]);
    int sockfd = socket(AF_INET,SOCK_DGRAM,0);
    string message;
    struct sockaddr_in server;
    bzero(&server,sizeof(server));
    server.sin_addr.s_addr = inet_addr(serverip.c_str());
    server.sin_port = htons(serverport);
    server.sin_family = AF_INET;
    socklen_t len = sizeof(server);
    char inbuffer[1024];
while(true){
   
    cout<<"请输入："<<endl;
    getline(cin,message);
    cout<<message<<endl;
    sendto(sockfd,message.c_str(),message.size(),0,(struct sockaddr*)&server,len);
    cout<<message<<endl;
    struct sockaddr_in temp;
    socklen_t lon = sizeof(temp);
    ssize_t s = recvfrom(sockfd,inbuffer,sizeof(inbuffer)-1,0,(struct sockaddr*)&temp,&lon);//接收服务端发来的消息
    cout<<s<<endl;
    if(s<0){
         cout<<strerror(errno)<<endl;
         continue;
    }
    inbuffer[s] = 0;
    //处理数据
    string info = inbuffer;
    string echo_string = "server echo#" + info;
    cout<<"woqu"<<endl;
   
}
    return 0;
}